package com.aisi.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Author: shenjianZ
 * @Date: 2024/2/15 18:28
 * @Description:
 */

@Component
public class FlowUtils {

    @Resource
    private StringRedisTemplate template;
    public boolean limitOnceCheck(String key ,int blockTime){
        if(Boolean.TRUE.equals(template.hasKey(key))){
            return false;
        }else{
            template.opsForValue().set(key,"",blockTime, TimeUnit.SECONDS);
            return true;
        }
    }
}
